#pragma once
#include "IXcpHostSite.h"
#include "CXcpDList.h"
#include "EncodedPtr.h"
class CValue;

class CCommonMinVerPrompt;

//Xcp_IAutomationPeer
class CControlBase :
	public IXcpHostSite
{
public: 
	CControlBase();
	virtual ~CControlBase();
	XINT32 IsInit();
	virtual HRESULT Init();
	XINT32 IsStarted();
	virtual struct IXcpDispatcher * GetXcpDispatcher();
	XINT32 IsContextMenu();
	virtual struct IPALUri * GetBaseUri();
	virtual struct IPALUri * GetSecurityUri();
	virtual HRESULT SetAppUri(struct IPALUri * pAppUri);
	void ResetAppUri();
	HRESULT OnPaint(void * hdcDraw, struct XRECT_WH * prcBounds);
protected: 

	typedef HRESULT (__stdcall * PFNXX)(struct IDependencyObject *, struct IDependencyObject *);
	typedef HRESULT (__stdcall *PFNXXX)(void *, struct IDependencyObject *, struct IDependencyObject *, class CXString *, int, struct IScriptObject *, PFNXX *);
	HRESULT UpdateSource(PFNXXX pFn);
public: 
	virtual HRESULT UpdateSource() = 0;
	virtual void DoMinVerNotifications();
	virtual void ShowMinVerWindow() = 0;
	virtual void Stop();
	static void setPlatformUtilities(struct IPlatformUtilities * pUtilities);
	virtual struct IXcpBrowserHost * GetBrowserHost();
	virtual HRESULT GetDefaultThemeResourceDictionaryString(XUINT32 cAssemblyNameString, XUINT16 * pAssemblyNameString, CXString * * ppResourceDictionaryString);
	virtual XINT32 IsInitialized();
	void ShowContextMenu(void *);
	virtual XUINT32 GetIdentity();
	virtual HRESULT GetAccessibilityObject(struct IDependencyObject * * ppAccessibility);
	virtual void ControlFreeString(XUINT16 * *) = 0;
	virtual HRESULT IsDependencyObjectValid(struct IDependencyObject * pDO);
	virtual void * AddTrackableObject(struct ITrackableObject * pObject);
	virtual HRESULT RemoveTrackableObject(void * index);
	virtual HRESULT ClearTrackableObjects();
	virtual HRESULT IsAutoUpgrade(XINT32 * pfAutoUpgrade);
	virtual HRESULT IsRuntimeVersionSupported(XINT32 * pfSupported);
	virtual HRESULT IsInstalledVersionSupported(XINT32 * pfSupported);
	virtual HRESULT IsVersionSupported(CXString * pVersion, XINT32 * pfSupported, CXString * pCheckVersion);
	struct VersionComponents
	{
	public: 
		XINT32 major;
		XINT32 minor;
		XINT32 build;
		XINT32 revision;
		VersionComponents();
	};
private: 
	HRESULT CrackVersionString(CXString * pVersion, struct CControlBase::VersionComponents * pVersionStruct);
public: 
	virtual HRESULT CrackVersionString(CXString * pVersion, XUINT32 * puMajorVersion, XUINT32 * puMinorVersion, XUINT32 * puBuildNumber, XUINT32 * puRevisionNumber);
	virtual XUINT16 * GetSourceString();
	virtual XBOOL GetEnableOverdrawHeatMap() const;
	virtual void SetEnableOverdrawHeatMap(XBOOL bEnabled);
	virtual XINT32 GetEnableFrameRateCounter() const;
	virtual void SetEnableFrameRateCounter(XINT32 bEnabled);
	virtual XINT32 GetEnableCacheVisualization() const;
	virtual void SetEnableCacheVisualization(XINT32 bEnabled);
	virtual void SetAllowExternalCallersFromXDomain(enum XDomainAccess eAllow);
	virtual enum XDomainAccess GetAllowExternalCallersFromXDomain();
	virtual XBOOL IsHostBrowser();
	virtual XBOOL IsHostCustomHost();
	virtual XBOOL IsJupiterNative();
	virtual XBOOL IsPrivacyModeCheckNeeded();
	virtual void * GetXcpControlWindow();
	virtual void * GetControlOrFullScreenWindow();
	virtual void SetMouseCapture(XBOOL fState);
	virtual XBOOL GetIsCrossDomainSource();
	virtual XBOOL GetIsRedirectedSource();
	virtual XFLOAT GetZoomFactor();
	virtual HRESULT UIAClientsAreListening(enum UIAXcp::APAutomationEvents eAutomationEvent);
	virtual HRESULT UIARaiseAutomationEvent(struct IAutomationPeer * pAP, enum UIAXcp::APAutomationEvents eAutomationEvent);
	virtual HRESULT UIARaiseAutomationPropertyChangedEvent(struct IAutomationPeer * pAP, enum UIAXcp::APAutomationProperties eAutomationProperty, CValue * oldValue, CValue * newValue);
	virtual HRESULT GetUIAWindow(void * hWnd, void * * ppUIAWindow);
	virtual HRESULT GetAccessibleRootObjectReference(void * hWnd, unsigned long dwFlags, unsigned long dwObjId, unsigned long * pdwReference, XBOOL * pbHandled);
	virtual XBOOL IsUIAutomationCoreSupported();
	virtual HRESULT IsAppVersionSupported(CXString * pVersion);
	virtual HRESULT OnSourceRedirected(struct IPALUri * pFinalSourceUri);
	virtual HRESULT GetProductId(CXString * * ppProductId);
	virtual HRESULT GetInstanceId(CXString * * ppInstanceId);
	virtual HRESULT OnPluginWindowChanged();
	virtual HRESULT OnFirstFrameDrawn();


private: 
	HRESULT InterpretSourceString(XUINT16 * wszSource, enum SourceType * pSourceType, CXString * * ppstrXaml, struct IPALUri * * ppUri);
protected: 
	virtual HRESULT CheckGraphicsSupportOverrides();
	virtual HRESULT SetMinVerSource();
	void Deinit();
	HRESULT GetClientURI();
	typedef int (__stdcall *PFNInternalHandler)(struct IDependencyObject *, struct IDependencyObject *);
	static HRESULT ScriptCallback(void * pControl, struct IDependencyObject * pSender, struct IDependencyObject * pe, CXString * pstrName, XINT32 flags, struct IScriptObject * pScriptObject, PFNInternalHandler  * pInternalHandler);
	HRESULT CheckReentrancy();
	XINT32 m_fInitialized;
	XINT32 fReady;
	struct IPALUri * m_pBaseUri;
	struct IPALUri * m_pDocUri;
	XUINT16 * m_bstrSource;
	XBOOL m_bOverdrawHeatMap;
	XINT32 m_bFrameCounter;
	XINT32 m_bCacheVisualization;
	XINT32 m_bEnableRedrawRegions;
	XINT32 m_bContextMenu;
	XINT32 m_bStarted;
	XINT32 m_bFirstLoad;
	XUINT16 * m_bstrBackgroundColor;
	XUINT16 * m_bstrMinVersion;
	CCommonMinVerPrompt * m_pMinVerPrompt;
	XUINT16 * m_bstrAutoUpgrade;
	XUINT32 m_uHeight;
	XUINT32 m_uWidth;
	XINT32 m_bMouseCaptured;
	struct IXcpDispatcher * m_pDispatcher;
	struct IXcpBrowserHost * m_pBH;
	struct IXcpHostCallback * m_pXcpHostCallback;
	XINT32 m_bHardenOM;
	static EncodedPtr<IPlatformUtilities> s_pUtilities;
	XBOOL m_bCrossDomainSource;
	XBOOL m_bRedirectedSource;
	enum XDomainAccess m_eAllowExternalCallersFromXDomain;
	XUINT16 * m_bstrProductId;
	XUINT16 * m_bstrInstanceId;
private: 
	struct IDependencyObject * m_pAccessible;
	CXcpDList<ITrackableObject> m_trackableObjList;
	XUINT32 m_objIdentity;
};

